<?php

namespace app\admin\model\rgjubao;

use think\Model;

/**
 *
 * 未成年
 */
class Wcn extends Model
{


    // 表名
    protected $name = 'rgjubao_wcn';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_text',
        'r_type_text',
        'r_sex_text',
        'f_starttime_text',
        'f_endtime_text',
        'f_isgang_text',
        'f_num_text',
        'f_type_text',
        'status_text'
    ];



    public function getTypeList()
    {
        return ['personal' => __('Type personal')];
        return ['personal' => __('Type personal'), 'company' => __('Type company')];
    }

    public function getRTypeList()
    {
        return ['personal' => __('R_type personal')];
        return ['personal' => __('R_type personal'), 'company' => __('R_type company')];
    }

    public function getRSexList()
    {
        return ['0' => __('R_sex 0'), '1' => __('R_sex 1'), '2' => __('R_sex 2')];
    }

    public function getFIsgangList()
    {
        return ['0' => __('F_isgang 0'), '1' => __('F_isgang 1'), '2' => __('F_isgang 2')];
    }

    public function getFNumList()
    {
        return ['0' => __('F_num 0'), '1' => __('F_num 1'), '2' => __('F_num 2'), '4' => __('F_num 4'), '11' => __('F_num 11'), '50' => __('F_num 50')];
    }

    public function getFTypeList()
    {
        return ['1' => __('F_type 1'), '2' => __('F_type 2'), '3' => __('F_type 3'), '4' => __('F_type 4'), '5' => __('F_type 5'), '6' => __('F_type 6'), '7' => __('F_type 7')];
    }

    public function getStatusList()
    {
        return ['1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getRTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['r_type']) ? $data['r_type'] : '');
        $list = $this->getRTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getRSexTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['r_sex']) ? $data['r_sex'] : '');
        $list = $this->getRSexList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getFStarttimeTextAttr($value, $data)
    {
        return isset($data['f_starttime']) ? $data['f_starttime'] : '';
       /* $value = $value ? $value : (isset($data['f_starttime']) ? $data['f_starttime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;*/
    }


    public function getFEndtimeTextAttr($value, $data)
    {
        return (isset($data['f_endtime']) ? $data['f_endtime'] : '');
        $value = $value ? $value : (isset($data['f_endtime']) ? $data['f_endtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getFIsgangTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['f_isgang']) ? $data['f_isgang'] : '');
        $list = $this->getFIsgangList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getFNumTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['f_num']) ? $data['f_num'] : '');
        $list = $this->getFNumList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getFTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['f_type']) ? $data['f_type'] : '');
        $valueArr = explode(',', $value);
        $list = $this->getFTypeList();
        return implode(',', array_intersect_key($list, array_flip($valueArr)));
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setFStarttimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setFEndtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setFTypeAttr($value)
    {
        return is_array($value) ? implode(',', $value) : $value;
    }
    public function harmMinors($data)
    {
        unset($data['id']);
        unset($data['status']);
        unset($data['createtime']);
        unset($data['updatetime']);
        return $this->data($data)->allowField(true)->isUpdate(false)->save();
        // return $this->allowField(true)->strict(false)->insertGetId($data);
    }

}
